package com.huxun.utils;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class PageUtils<T> {

    private int pageSize;
    private int pageIndex;
    private int pageCount; //总页数
    private int totalCount; //总条数
    private List<T> records; //每页数据

    private int numberStart=1;
    private int numberEnd;
    private List<Integer> numbers=new ArrayList<>();

    public PageUtils(int pageSize, int pageIndex, int totalCount, List<T> records) {
        this.pageSize = pageSize;
        this.pageIndex = pageIndex;
        this.totalCount = totalCount;
        this.records = records;
        this.pageCount=totalCount%pageSize==0?(totalCount/pageSize):(totalCount/pageSize+1);

        // 一共显示10个页面 动态伸缩
        if (this.pageCount <= 10) {
            this.numberStart = 1;
            this.numberEnd = pageCount;
        } else {
            this.numberStart = pageIndex - 4;
            this.numberEnd = pageIndex + 5;
            if (numberStart < 1) {
                this.numberStart = 1;
                this.numberEnd = 10;
            } else if (numberEnd > pageCount) {
                this.numberEnd = pageCount;
                this.numberStart = pageCount - 9;
            }
        }
        // 一共显示10个页面 动态伸缩

        for (int i =numberStart; i <=numberEnd ; i++) {
            numbers.add(i);
        }


    }
}
